/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.comm.mavlink;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 *
 * @author amalikov
 */
public class GpsRawInt implements MessagePayload {
	public long time_usec;
	public int lat;
	public int lon;
	public int alt;
	public short eph;
	public short epv;
	public short vel;
	public short cog;
	public byte fix_type;
	public byte satellites_visible;

	@Override
	public byte[] get() {
		ByteBuffer bb = ByteBuffer.allocate(256).order(ByteOrder.LITTLE_ENDIAN);
		bb.putLong(time_usec);
		bb.putInt(lat);
		bb.putInt(lon);
		bb.putInt(alt);
		bb.putShort(eph);
		bb.putShort(epv);
		bb.putShort(vel);
		bb.putShort(cog);
		bb.put(fix_type);
		bb.put(satellites_visible);
		return Arrays.copyOf(bb.array(), bb.position());
	}

	@Override
	public void set(byte[] data) {
		ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
		time_usec = bb.getLong();
		lat = bb.getInt();
		lon = bb.getInt();
		alt = bb.getInt();
		eph = bb.getShort();
		epv = bb.getShort();
		vel = bb.getShort();
		cog = bb.getShort();
		fix_type = bb.get();
		satellites_visible = bb.get();
	}
}
